<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>原型链继承</title>
  </head>

  <body>

  </body>
  <script>
    /* 
    组合继承：构造函数借用继承+原型链继承
    */
    function Person(name, age, gender) {
      this.name = name;
      this.age = age;
      this.gender = gender
    }
    Person.prototype.sayHi = () => {
      console.log("hello");
    }

    //原型继承
    Student.prototype = new Person();
    //把原型关系补上
    Student.prototype.constructor = Student;

    function Student(name, age, gender, studentId) {
      //借用Person构造函数的属性
      Person.call(this, name, age, gender);
      this.studentId = studentId;
    }
    Student.prototype.dohomeWork = function () {
      console.log("做作业");
    }

    let s1 = new Student("jason", 18, "male", 10001);
    console.log(s1);


    // 原型继承
    Teacher.prototype = new Person();
    //把原型关系补上
    Teacher.prototype.constructor = Teacher;

    function Teacher(name, age, gender, salary) {
      Person.call(this, name, age, gender);
      this.salary = salary;
    }
    Teacher.prototype.teaching = function () {
      console.log("我会教书");
    }
    let t1 = new Teacher("六老师", 60, 'female', 10000);
    console.log(t1);
  </script>

</html>